package com.example.mywechatprogram.service;

import com.example.mywechatprogram.entity.Response;
import com.example.mywechatprogram.entity.Word;
import com.example.mywechatprogram.mapper.WordMapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class WordService {
    @Autowired
    WordMapper wordMapper;
    public Response request(String userId,String bookId){
        try {
            List<Word> res =wordMapper.request(bookId,userId);
            if(res!=null)return new Response(Response.SERVICE_RUN_SUCCESSFULLY,res,"请求成功");
            else return new Response(Response.SERVICE_RUN_SUCCESSFULLY,null,"你背完所有单词啦");
        }catch (Exception e){
            System.out.println(e.getMessage());
            return new Response(Response.SERVICE_RUN_FIELD,null,"请求失败");
        }
    }
    public Response finish(int word_id,String userId,String bookId){
        try {
            int index= wordMapper.finish(word_id,userId,bookId);
            if(index==1)return new Response(Response.SERVICE_RUN_SUCCESSFULLY,null,"请求成功");
            else return new Response(Response.SERVICE_RUN_FIELD,null,"内部错误");
        }catch (Exception e){
            System.out.println(e.getMessage());
            return new Response(Response.SERVICE_RUN_FIELD,null,"内部错误");
        }
    }
}
